// FixTtxt.h: interface for the CFixTtxt class.
//
//////////////////////////////////////////////////////////////////////

#pragma once

#include "SmallUtilz.h"

class CFixTtxt
{
public:
	bool bFixTtxt(LPCTSTR lpSrc, LPCTSTR lpDst=NULL, int iFontSize=18, int iVideoDuration=0);
	bool bAdjustTime(LPCTSTR lpSrc, LPCTSTR lpDst=NULL, int iTimePlus=0);
	CFixTtxt();
	virtual ~CFixTtxt();

protected:
	void inline fwriteCRLF(FILE *f) {
		static BYTE CRLF[] = {0x0d, 0x0a};
		fwrite(CRLF, 1, 2, f);
	}
	TCHAR * tcDecode(char *ch, int iLen, int &iNewLen);
	void FixIt(char *ch, int iLen, FILE *f, char *cfontSize);
	int iFind(char *chSrc, int iSize, char *chStr, int iStart);
	TCHAR tcDecodeUnicode(char *ch, int &iDecodedLen);
	void Write1Style(FILE *f, int iFrom, int iTo, char *Style, char *cfontSize);
	void WriteStyles(FILE *f, char *Styles, int iLen, char *cfontSize);
	void WriteXMLStr(FILE *f, TCHAR *tc, int iLen);
	char * chGetValue(char *chTag, int iLen, char *chElement);
	void ApplyEffect(char *chEffect, int iLen, char *chTag, int iTagLen);
	int iCutOut(TCHAR *tcText, int buffersize, char *chProp, int iLen, int iP1, int iP2);
	char * chGetColorValue(char *chColor);
	char * chGetColorTag(TCHAR *tc, int iLen);
	bool bFindFONTTagClose(TCHAR *tcText, int iLen, int iFrom, int &iBegin, int &iEnd);
	bool bFindHTMLTagRev(TCHAR *tcText, int iLen, int &iBegin, int &iEnd);
	int iFixFontTags(TCHAR *tcText, int buffersize, char *chProp, int iLen);
	int iReplaceISO8859_1Again(TCHAR *tcText, int buffersize, char *chProp, int iLen);
	int iRemoveNullLines(TCHAR *tcText, int buffersize, char *chProp, int iLen);

	inline int isdigit_char(char c) { return __isascii(c) && isdigit(c); }
	inline int isxdigit_char(char c) { return __isascii(c) && isxdigit(c); }
	inline int isalnum_char(char c) { return __isascii(c) && isalnum(c); }
};
